// pages/teacher/mine/mineClass/mineClass.js
var app = getApp();
import {teacher_active} from "../../../../asserts/js/common/barList";
import {initCourseInit, getCourseParam} from "../../../../asserts/js/common/shareFun";
import {post} from "../../../../asserts/js/request";
Page({

  /**
   * 页面的初始数据
   */
  data: {
    barList: teacher_active(1),
    top: app.globalData.bottom + 'px',
    buttom_title: {
      title1: '舞种',
      title2: '课程类型'
    },
    class_list: [
      {
        code:"a",
        name: "初级班·拉丁",
        stu_num: "24",
        homework_num: "3",
        book_num: "15"
      },
      {
        code:"b",
        name: "高级班·拉丁",
        stu_num: "21",
        homework_num: "4",
        book_num: "18"
      },
      {
        code:"b",
        name: "高级班·拉丁",
        stu_num: "21",
        homework_num: "4",
        book_num: "18"
      },
      {
        code:"b",
        name: "高级班·拉丁",
        stu_num: "21",
        homework_num: "4",
        book_num: "18"
      },
      {
        code:"b",
        name: "高级班·拉丁",
        stu_num: "21",
        homework_num: "4",
        book_num: "18"
      },
      {
        code:"b",
        name: "高级班·拉丁",
        stu_num: "21",
        homework_num: "4",
        book_num: "18"
      }
    ],
    tabObj: {},
    alter_show: false,
    danceKind: [],
    courseLevel: [],
    courseNature: [],
    className: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var obj = initCourseInit(app.globalData.enum_courseTypes, app.globalData.enum_courseLevels, app.globalData.enum_courseNature)
    this.setData({
      tabObj: obj
    })
    this.getData()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  selectBoxShow: function(){
    this.setData({
      alter_show: true
    })
  },
  alterCancel: function() {
    this.setData({
      alter_show: false
    })
  },
  back: function(){
    wx.navigateBack({
      delta: 0
    })
  },
  getCourses: function(data) {
    console.log(data);
    var ori = data.currentTarget.dataset.item;
    wx.navigateTo({
      url: '/pages/teacher/mine/classCourse/classCourse?classId=' + ori.classId,
    })
  },
  selectSure: function(e) {
    let this_ = this;
    var paramList = getCourseParam(e.detail.tabList);
    this.setData({
      danceKind: paramList.danceKind,
      courseLevel: paramList.courseLevel,
      courseNature: paramList.courseNature,
      alter_show: false
    }, function(){
      this_.getData()
    })
  },
  nameChange: function(e) {
    this.setData({
      className: e.detail.value
    })
  },
  getData: function() {
    let this_ = this
    console.log(this.data.danceKind, this.data.courseLevel, this.data.courseNature, this.data.className)
    post("queryMyClass", {
      teacherId: app.globalData.teacherInfo.teacherId,
      danceKind: this.data.danceKind.join("|"),
      courseLevel: this.data.courseLevel.join("|"),
      courseNature: this.data.courseNature.join("|"),
      className: this.data.className
    }).then(data => {
      this_.setData({
        class_list: data.classInfo.map(item =>{
          item.modiTime = item.modiTime?item.modiTime.split(" ")[0]:""
          return item
        })
      })
    })
  }
})